package com.hxzy.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hxzy.comm.Constants;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author wy
 * @Description TODO
 * @Date 2023/5/25 14:39
 * @Version 1.0
 */
@RestController
public class FanoutController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private ObjectMapper objectMapper;

    @PostMapping(value = "/fanout/send")
    public String fanout(@RequestBody Map<String,Object> map) throws JsonProcessingException {
        String json=this.objectMapper.writeValueAsString(map);

        this.rabbitTemplate.convertAndSend(Constants.FANOUT_EXCHNAGE_DEMO,"",json);

        return "fanout模型-消息发送成功";

    }
}
